package org.example.Utils;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.TankGan.pojo.Bullet.Bullet;
import org.example.TankGan.pojo.Enemy.EnemyTank;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 * @author cc
 * @date 2021/4/20 14:28
 * @Description
 */
public class EnemiesInit {
    private static int Enemy_x=0;
    private static int Enemy_y=0;
    private static int EnemyNumbers=3;
    private static int EnemyDrection=2;
    private static int speeed=20;
    private static int type=1;
    private static boolean setBullets=false;
    private static int setBulletNums=1;
    private static EnemyTank enemyTank;

    private static Bullet bullet =new Bullet();
    private static Vector<Bullet> bullets = new Vector<>();
    private static Vector<EnemyTank> enemyTanks;

    public EnemiesInit() {
    }


    /**
     * 所有参数都用的默认值
     * @author sosmcc
     * @param
     */
    public static Vector<EnemyTank> inits() {
        enemyTanks = new Vector<EnemyTank>(EnemyNumbers);
        for (int i = 0; i < enemyTanks.capacity(); i++) {
             enemyTank = new EnemyTank(((100 + Enemy_x) * (i + 1)), ((50 + Enemy_y)), EnemyDrection, speeed, type);
            Vector<Bullet> bullet = bulletinit(EnemyDrection);
            for (Bullet temp : bullet) {
                enemyTank.getBullets().add(temp);
                new Thread(temp).start();
            }
            enemyTanks.add(enemyTank);
            new Thread(enemyTank).start();

        }
        return enemyTanks;
    }
    public static Vector<EnemyTank> inits(int bulletNumbs,int speed,int EnemyNumbes_temp,int EnemyBulletSpeed) {
        if (bulletNumbs>1){
            setBullets=true;
            setBulletNums =bulletNumbs;
        }
        speeed = speed;
        EnemyNumbers = EnemyNumbes_temp;
        enemyTanks = new Vector<EnemyTank>(EnemyNumbers);
        for (int i = 0; i < enemyTanks.capacity(); i++) {
            //随机一个朝向
            EnemyDrection = ((int)(Math.random()*4));
            enemyTank = new EnemyTank(((100 + Enemy_x) * (i + 1)), ((50 + Enemy_y)), EnemyDrection, speeed, type,EnemyBulletSpeed);
            enemyTanks.add(enemyTank);
            new Thread(enemyTank).start();

        }
        //把敌人坦克的同伴设置给当前敌人目的是防止重叠

        for (EnemyTank tank : enemyTanks) {
            tank.setEnemyTanks(enemyTanks);

        }

        return enemyTanks;
    }
    public static Vector<EnemyTank> inits(int bulletNumbs,int EnemyNumbes_temp) {
        if (bulletNumbs>1){
            setBullets=true;
            setBulletNums =bulletNumbs;
        }
        EnemyNumbers = EnemyNumbes_temp;
        enemyTanks = new Vector<EnemyTank>(EnemyNumbers);
        for (int i = 0; i < enemyTanks.capacity(); i++) {
            enemyTank = new EnemyTank(((100 + Enemy_x) * (i + 1)), ((50 + Enemy_y)), EnemyDrection, speeed, type);
            Vector<Bullet> bullet = bulletinit(EnemyDrection);
            for (Bullet temp : bullet) {
                enemyTank.getBullets().add(temp);
                new Thread(temp).start();
            }
            enemyTanks.add(enemyTank);
            new Thread(enemyTank).start();

        }
        return enemyTanks;
    }
   public static Vector<EnemyTank> initTest(){
       enemyTanks = new Vector<EnemyTank>(EnemyNumbers);
       for (int i = 0; i < enemyTanks.capacity(); i++) {
           enemyTank = new EnemyTank(((100 + Enemy_x) * (i + 1)), ((50 + Enemy_y)), EnemyDrection, speeed, type);
//           Vector<Bullet> bullet = bulletinit(EnemyDrection);
//           for (Bullet temp : bullet) {
//               enemyTank.getBullets().add(temp);
//               new Thread(temp).start();
//           }
           enemyTanks.add(enemyTank);
           new Thread(enemyTank).start();

       }
       return enemyTanks;
   }
   //在程序开始的时候画上子弹
   private static Vector<Bullet> bulletinit(int EnemyDrection ){
       switch (EnemyDrection){
            case 0:
            case 2:
                if (setBullets){
                    for (int i = 0; i < setBulletNums; i++) {
                        Bullet temp = new Bullet(enemyTank.getX() + (20), enemyTank.getY() + (60*i), enemyTank.getDrection(), enemyTank.getSpeed() + 20);
                        bullets.add(temp);
                    }
                }else {
                     bullet = new Bullet(enemyTank.getX() + (20), enemyTank.getY() + 60, enemyTank.getDrection(), enemyTank.getSpeed() + 20);
                    bullets.add(bullet);
                }
                break;
            case 1:
            case 3:
                if (setBullets){
                    for (int i = 0; i < setBulletNums; i++) {
                        Bullet temp = new Bullet(enemyTank.getX() + (20*i), enemyTank.getY() + (60), enemyTank.getDrection(), enemyTank.getSpeed() + 20);
                        bullets.add(temp);
                    }
                }else {
                    bullet = new Bullet(enemyTank.getX() + (20), enemyTank.getY() + 60, enemyTank.getDrection(), enemyTank.getSpeed() + 20);
                    bullets.add(bullet);
                }
                break;
        }
       return bullets;
   }

}
